//
//  CostTableViewCell.swift
//  HuaYun
//
//  Created by enghou on 2019/1/15.
//  Copyright © 2019 xyxorigation. All rights reserved.
//

import UIKit

class CostTableViewCell: UITableViewCell {

    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var incomePlanLabel: UILabel!
    @IBOutlet weak var incomeExecuteLabel: UILabel!
    @IBOutlet weak var incomeRatioLabel: UILabel!
    private var _model: JSON?
    var model: JSON?{
        get{
            return _model
        }
        set{
            if _model != newValue {
                _model = newValue
                self.titleLabel.text = _model?["name"].string
                let plan = _model?["planBudgetCost"].int ?? 0
                let planreal = plan / 1000000
                self.incomePlanLabel.text = String(planreal).rmbformat//String(plan / 100.0).rmbformat
                let execute = _model?["planExecuteCost"].int ?? 0
                let executereal = execute / 1000000
                self.incomeExecuteLabel.text = String(executereal).rmbformat
                var ratio = 0.0
                if planreal > 0 {
                    ratio = Double(executereal / planreal * 100)
                }
                self.incomeRatioLabel.text = String(format: "%.2f", ratio) + "%"
            }
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.contentView.backgroundColor = UIColor.tableSeparator
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
